{"ast":null,"code":"function getError(option, xhr) {\n  var msg = \"cannot \".concat(option.method, \" \").concat(option.action, \" \").concat(xhr.status, \"'\");\n  var err = new Error(msg);\n  err.status = xhr.status;\n  err.method = option.method;\n  err.url = option.action;\n  return err;\n}\nfunction getBody(xhr) {\n  var text = xhr.responseText || xhr.response;\n  if (!text) {\n    return text;\n  }\n  try {\n    return JSON.parse(text);\n  } catch (e) {\n    return text;\n  }\n}\nexport default function upload(option) {\n  // eslint-disable-next-line no-undef\n  var xhr = new XMLHttpRequest();\n  if (option.onProgress && xhr.upload) {\n    xhr.upload.onprogress = function progress(e) {\n      if (e.total > 0) {\n        e.percent = e.loaded / e.total * 100;\n      }\n      option.onProgress(e);\n    };\n  } // eslint-disable-next-line no-undef\n\n  var formData = new FormData();\n  if (option.data) {\n    Object.keys(option.data).forEach(function (key) {\n      var value = option.data[key]; // support key-value array data\n\n      if (Array.isArray(value)) {\n        value.forEach(function (item) {\n          // { list: [ 11, 22 ] }\n          // formData.append('list[]', 11);\n          formData.append(\"\".concat(key, \"[]\"), item);\n        });\n        return;\n      }\n      formData.append(key, value);\n    });\n  } // eslint-disable-next-line no-undef\n\n  if (option.file instanceof Blob) {\n    formData.append(option.filename, option.file, option.file.name);\n  } else {\n    formData.append(option.filename, option.file);\n  }\n  xhr.onerror = function error(e) {\n    option.onError(e);\n  };\n  xhr.onload = function onload() {\n    // allow success when 2xx status\n    // see https://github.com/react-component/upload/issues/34\n    if (xhr.status < 200 || xhr.status >= 300) {\n      return option.onError(getError(option, xhr), getBody(xhr));\n    }\n    return option.onSuccess(getBody(xhr), xhr);\n  };\n  xhr.open(option.method, option.action, true); // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179\n\n  if (option.withCredentials && 'withCredentials' in xhr) {\n    xhr.withCredentials = true;\n  }\n  var headers = option.headers || {}; // when set headers['X-Requested-With'] = null , can close default XHR header\n  // see https://github.com/react-component/upload/issues/33\n\n  if (headers['X-Requested-With'] !== null) {\n    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');\n  }\n  Object.keys(headers).forEach(function (h) {\n    if (headers[h] !== null) {\n      xhr.setRequestHeader(h, headers[h]);\n    }\n  });\n  xhr.send(formData);\n  return {\n    abort: function abort() {\n      xhr.abort();\n    }\n  };\n}","map":{"version":3,"names":["getError","option","xhr","msg","concat","method","action","status","err","Error","url","getBody","text","responseText","response","JSON","parse","e","upload","XMLHttpRequest","onProgress","onprogress","progress","total","percent","loaded","formData","FormData","data","Object","keys","forEach","key","value","Array","isArray","item","append","file","Blob","filename","name","onerror","error","onError","onload","onSuccess","open","withCredentials","headers","setRequestHeader","h","send","abort"],"sources":["/data/messenger.client/node_modules/rc-upload/es/request.js"],"sourcesContent":["function getError(option, xhr) {\n  var msg = \"cannot \".concat(option.method, \" \").concat(option.action, \" \").concat(xhr.status, \"'\");\n  var err = new Error(msg);\n  err.status = xhr.status;\n  err.method = option.method;\n  err.url = option.action;\n  return err;\n}\n\nfunction getBody(xhr) {\n  var text = xhr.responseText || xhr.response;\n\n  if (!text) {\n    return text;\n  }\n\n  try {\n    return JSON.parse(text);\n  } catch (e) {\n    return text;\n  }\n}\n\nexport default function upload(option) {\n  // eslint-disable-next-line no-undef\n  var xhr = new XMLHttpRequest();\n\n  if (option.onProgress && xhr.upload) {\n    xhr.upload.onprogress = function progress(e) {\n      if (e.total > 0) {\n        e.percent = e.loaded / e.total * 100;\n      }\n\n      option.onProgress(e);\n    };\n  } // eslint-disable-next-line no-undef\n\n\n  var formData = new FormData();\n\n  if (option.data) {\n    Object.keys(option.data).forEach(function (key) {\n      var value = option.data[key]; // support key-value array data\n\n      if (Array.isArray(value)) {\n        value.forEach(function (item) {\n          // { list: [ 11, 22 ] }\n          // formData.append('list[]', 11);\n          formData.append(\"\".concat(key, \"[]\"), item);\n        });\n        return;\n      }\n\n      formData.append(key, value);\n    });\n  } // eslint-disable-next-line no-undef\n\n\n  if (option.file instanceof Blob) {\n    formData.append(option.filename, option.file, option.file.name);\n  } else {\n    formData.append(option.filename, option.file);\n  }\n\n  xhr.onerror = function error(e) {\n    option.onError(e);\n  };\n\n  xhr.onload = function onload() {\n    // allow success when 2xx status\n    // see https://github.com/react-component/upload/issues/34\n    if (xhr.status < 200 || xhr.status >= 300) {\n      return option.onError(getError(option, xhr), getBody(xhr));\n    }\n\n    return option.onSuccess(getBody(xhr), xhr);\n  };\n\n  xhr.open(option.method, option.action, true); // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179\n\n  if (option.withCredentials && 'withCredentials' in xhr) {\n    xhr.withCredentials = true;\n  }\n\n  var headers = option.headers || {}; // when set headers['X-Requested-With'] = null , can close default XHR header\n  // see https://github.com/react-component/upload/issues/33\n\n  if (headers['X-Requested-With'] !== null) {\n    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');\n  }\n\n  Object.keys(headers).forEach(function (h) {\n    if (headers[h] !== null) {\n      xhr.setRequestHeader(h, headers[h]);\n    }\n  });\n  xhr.send(formData);\n  return {\n    abort: function abort() {\n      xhr.abort();\n    }\n  };\n}"],"mappings":"AAAA,SAASA,QAAQ,CAACC,MAAM,EAAEC,GAAG,EAAE;EAC7B,IAAIC,GAAG,GAAG,SAAS,CAACC,MAAM,CAACH,MAAM,CAACI,MAAM,EAAE,GAAG,CAAC,CAACD,MAAM,CAACH,MAAM,CAACK,MAAM,EAAE,GAAG,CAAC,CAACF,MAAM,CAACF,GAAG,CAACK,MAAM,EAAE,GAAG,CAAC;EACjG,IAAIC,GAAG,GAAG,IAAIC,KAAK,CAACN,GAAG,CAAC;EACxBK,GAAG,CAACD,MAAM,GAAGL,GAAG,CAACK,MAAM;EACvBC,GAAG,CAACH,MAAM,GAAGJ,MAAM,CAACI,MAAM;EAC1BG,GAAG,CAACE,GAAG,GAAGT,MAAM,CAACK,MAAM;EACvB,OAAOE,GAAG;AACZ;AAEA,SAASG,OAAO,CAACT,GAAG,EAAE;EACpB,IAAIU,IAAI,GAAGV,GAAG,CAACW,YAAY,IAAIX,GAAG,CAAC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